<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>地图选车</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            font-size: 12px;
            -webkit-touch-callout: none;
            /*系统默认菜单被禁用*/
            -webkit-user-select: none;
            /*webkit浏览器*/
            -khtml-user-select: none;
            /*早期浏览器*/
            -moz-user-select: none;
            /*火狐*/
            -ms-user-select: none;
            /*IE10*/
            user-select: none;
        }
        
        html,
        body {
            -webkit-overflow-scrolling: touch;
            -webkit-tab-highlight-color: rgba(0, 0, 0, 0);
        }
        
        input {
            -webkit-user-select: auto;
            /*webkit浏览器*/
        }
        
        textarea {
            -webkit-user-select: auto;
            /*webkit浏览器*/
        }
        
        html,
        body,
        #container,
        .main {
            width: 100%;
            height: 100%;
            -webkit-overflow-scrolling: touch;
        }
        
        .main {
            position: relative;
            background-color: #e4e5e8;
        }
        
        .refresh {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 46px;
            height: 46px;
            background: #fff;
            border-radius: 6px;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }
        
        .ref {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: all .5s ease-in-out;
        }
        
        .prompt,
        .loading,
        .hint {
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 999;
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        
        .active-prompt,
        .active-loading {
            display: flex;
        }
        
        .promptBox {
            background: #fff;
            width: 60%;
            border-radius: 10px;
            border: 1px solid #f1f1f1;
        }
        
        .promptTitle {
            padding: 20px 0;
            text-align: center;
        }
        
        .btns {
            display: flex;
            width: 100%;
            height: 40px;
            border-top: 1px solid #f1f1f1;
        }
        
        .btn {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .confirm {
            color: #0066FF;
        }
        
        .cancel {
            color: #000;
            border-right: 1px solid #f1f1f1;
        }
        
        .amap-logo,
        .amap-copyright {
            display: none!important;
        }
        /* 加载 */
        
        .loadingbox {
            width: 6rem;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            background: rgba(0, 0, 0, .6);
            border-radius: 6px;
        }
        
        .icon {
            width: 4rem;
            height: 4rem;
            display: flex;
            justify-content: center;
            align-items: center;
            animation: rotateIcon 1s linear infinite;
            -webkit-animation: rotateIcon 1s linear infinite;
        }
        /* .loadingImg{width:60%;height:60%;} */
        
        .title {
            height: 30px;
            line-height: 30px;
            color: #fff;
        }
        
        .typeName {
            width: 60px;
            padding-right: 10px;
        }
        
        .content {
            flex: 1;
        }
        
        .anchorBL {
            display: none;
        }
        /* 提示 */
        
        @keyframes rotateIcon {
            0% {
                transform: rotate(0deg);
            }
            25% {
                transform: rotate(90deg);
            }
            50% {
                transform: rotate(180deg);
            }
            75% {
                transform: rotate(270deg);
            }
            100% {
                transform: rotate(360deg);
            }
        }
        
        @-webkit-keyframes rotateIcon {
            0% {
                -webkit-transform: rotate(0deg);
            }
            25% {
                -webkit-transform: rotate(90deg);
            }
            50% {
                -webkit-transform: rotate(180deg);
            }
            75% {
                -webkit-transform: rotate(270deg);
            }
            100% {
                -webkit-transform: rotate(360deg);
            }
        }
        
        #dropdown {
            width: 90%;
            height: 30px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            top: 10px;
            z-index: 9999;
            border-radius: 10px;
        }
        
        #dropdown .cs-select {
            width: 100%;
            height: 30px;
            outline-style: none;
            border: none;
        }
    </style>
</head>

<body>
    <div class="main">
        <div id="dropdown">
            <section>
                <select class="cs-select" id="select">
                    <option value="-1" selected></option>
                </select>
            </section>
        </div>
        <div id="container"></div>
        <!-- 刷新 -->
        <div class="refresh" onclick="refresh()">
            <div class="ref" id="ref">
                <img src="../img/ref.png" alt="ref" />
            </div>
        </div>
        <!-- 提示框 -->
        <div class="prompt" id="prompt">
            <div class="promptBox">
                <div class="promptTitle" id="promptTitle"></div>
                <div class="btns">
                    <div class="btn cancel" onclick="cancel()">取消</div>
                    <div class="btn confirm" onclick="confirm()">确定</div>
                </div>
            </div>
        </div>
        <!-- 加载框 -->
        <div class="loading" id="loading">
            <div class="loadingbox">
                <div class="icon">
                    <img src="../img/loading.png" alt="loading" class="loadingImg">
                </div>
                <div class="title">调度中...</div>
            </div>
        </div>
        <!-- 提示框 -->
        <!-- <div class="hint" id="hint">
			<div class="hintbox">
				<div class="title" id="title"></div>
			</div>
		</div> -->
        <div class="prompt" id="dispatch">
            <div class="promptBox">
                <div class="promptTitle" id="dispatchTitle"></div>
                <div class="btns">
                    <!-- <div class="btn cancel" onclick="cancel()">取消</div> -->
                    <div class="btn confirm" onclick="hideHint()">确定</div>
                </div>
            </div>
        </div>
    </div>
    <!-- uni 的 SDK -->
    <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js"></script>
    <script type="text/javascript" src="../js/jquery.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/busy-load/dist/app.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/busy-load/dist/app.min.js"></script>
    <script type="text/javascript" src="../common/config.js"></script>
    <!-- 百度key -->
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=aVzaHmwQnvjdpB2GZGaLPC80skdwuF50"></script>
    <!-- <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=09167f16fc0f56dcb23992867eddf13e"></script> -->
    <script type="text/javascript" src="../common/mock.js"></script>
    <script type="text/javascript" src="../js/InfoBox_min.js"></script>
    <script type="text/javascript">
        // document.addEventListener('UniAppJSBridgeReady', function() {
        // 创建地图
        // let map = new AMap.Map('container',{
        // 	resizeEnable:true
        // });
        let map;
        let isDispatch;
        let positions = []
        let prompt = document.getElementById("prompt");
        let loading = document.getElementById("loading");
        let dispatchTitle = document.getElementById("dispatchTitle");
        let dispatchHint = document.getElementById('dispatch');
        let promptTitle = document.getElementById('promptTitle');
        let infoWindow, info, timer = null;
        let deg = 360;
        let orderId, bool, urlData, accessToken, machineCode, nickname, dispathPhone, driverType, fleetdsId, carId, nodeSegment, roleNumber;
        let htmls, obj;
        let state; //调度状态
        let carIcon = new BMap.Icon('../img/car40x40.png', new BMap.Size(40, 40));
        let myGeo;
        let appPoint;
        // let openInfoList;  //接收打开的信息窗口
        window.lastInfoBox = null;
        window.onload = function() {
                urlData = getUrlData("info");
                urlData = decodeURIComponent(urlData);
                // if(!urlData){
                bool = JSON.parse(urlData).bool;
                isDispatch = JSON.parse(urlData).isDispatch ? JSON.parse(urlData).isDispatch : null
                orderId = JSON.parse(urlData).orderId;
                accessToken = JSON.parse(urlData).accessToken;
                machineCode = JSON.parse(urlData).machineCode;
                nickname = JSON.parse(urlData).nickname;
                dispathPhone = JSON.parse(urlData).dispathPhone;
                fleetdsId = JSON.parse(urlData).fleetdsId;
                nodeSegment = nodeSegment ? JSON.parse(JSON.stringify(nodeSegment)) : ''
                roleNumber = roleNumber ? JSON.parse(JSON.stringify(roleNumber)) : ''
                    //appPoint = JSON.parse(urlData).point;
                console.log(JSON.parse(urlData).accessToken);
                console.log(JSON.parse(urlData).machineCode);
                // }
                initMap();
            }　
            // function AddRunningDiv() {
            //     $("<div class=\"datagrid-mask\"></div>").css({
            //         display: "block",
            //         width: "100%",
            //         height: $(document).height()
            //     }).appendTo("body");
            //     $("<div class=\"datagrid-mask-msg\"></div>").html("正在处理，请稍候...").appendTo("body").css({
            //         display: "block",
            //         left: ($(document.body).outerWidth(true) - 190) / 2,
            //         top: ($(document).height() - 45) / 2
            //     });
            // }

        // function MoveRunningDiv() {
        //     $("div[class='datagrid-mask']").remove();
        //     $("div[class='datagrid-mask-msg']").remove();
        // }
        function DropDown(el) {
            this.dd = el;
            this.placeholder = this.dd.children('span');
            this.opts = this.dd.find('ul.dropdown > li');
            this.val = '';
            this.index = -1;
            this.initEvents();
        }
        DropDown.prototype = {
            initEvents: function() {
                var obj = this;
                obj.dd.on('click',
                    function(event) {
                        $(this).toggleClass('active');
                        return false;
                    });
                obj.opts.on('click',
                    function() {
                        var opt = $(this);
                        obj.val = opt.text();
                        obj.index = opt.index();
                        obj.placeholder.text('Gender: ' + obj.val);
                    });
            },
            getValue: function() {
                return this.val;
            },
            getIndex: function() {
                return this.index;
            }
        }

        $(function() {
            var dd = new DropDown($('#dd'));

            $(document).click(function() {
                // all dropdowns
                $('.wrapper-dropdown-1').removeClass('active');
            });

        });

        // $("#dropdown p").click(function() {
        //     var ul = $("#dropdown ul");
        //     if (ul.css("display") == "none") {
        //         ul.slideDown("fast");
        //     } else {
        //         ul.slideUp("fast");
        //     }
        // });
        // $("#dropdown ul li a").click(function() {
        //     var txt = $(this).text();
        //     $("#dropdown p").html(txt);
        //     $("#dropdown ul").hide();
        // });
        window.dang = function(val, fleid, catid, Type, name, dispname) {
            $(".main").busyLoad("show", {
                spinner: "circles",
                animation: "slide"
            });
            //AddRunningDiv()
            if (orderId) {
                let obj = {
                    orderId: orderId || null,
                    driverId: fleid || null,
                    carId: catid || null,
                    dispatchName: nickname || null,
                    dispathPhone: dispathPhone || null,
                    nodeContent: `${nickname}指定给司机: ${dispname} 派送订单，完成订单调度`,
                    nodeSegment: nodeSegment ? nodeSegment : null,
                    roleNumber: roleNumber ? roleNumber : Type == 3 ? 2 : 3
                }
                $.ajax({
                    url: `${config.baseURL}/logistic/dispatch/insertOrderDispatchOne`,
                    type: 'post',
                    dateType: 'json',
                    headers: {
                        'Content-Type': 'application/json;charset=utf8',
                        accessToken: accessToken,
                        equipmentType: 1,
                        machineCode: machineCode
                    },
                    data: JSON.stringify(obj),
                    success: (res) => {
                        $(".main").busyLoad("hide");
                        //MoveRunningDiv()
                        if (res.state == 200) {
                            showHint('订单调度成功');
                        } else {
                            showHint('订单调度失败');
                        }
                    }
                })
            }
        }

        function initMap() {
            let lng = 114.065702;
            let lat = 22.549257;
            // let lng, lat;
            // if (value) {
            //     lng = value.lng;
            //     lat = value.lat;
            // } else {
            //     lng = 116.331398;
            //     lat = 39.897445;
            // }
            // 创建地图
            map = new BMap.Map("container", {
                minZoom: 6,
                maxZoom: 18,
                enableMapClick: false
            }); // 创建地图实例
            point = new BMap.Point(lng, lat); // 创建点坐标
            map.centerAndZoom(point, 6); // 初始化地图，设置中心点坐标和地图级别  
            map.enableKeyboard(); //启用键盘操作
            map.setMinZoom(6); //设置地图允许的最小级别。
            map.setMaxZoom(18); //设置地图允许的最大级别。
            map.enableScrollWheelZoom();
            //后台请求司机位置数据显示覆盖物
            getDriverAddress()
                //ajaxMarker()
                //operationOrder();
        }

        function getDriverAddress() {
            $.get(`${config.requestUrl}//gps/findCarGpsInfoList`, (res) => {
                if (res.state == 200) {
                    console.log(res)
                    let data = res.data
                    for (let i in data) {
                        positions.push(data[i])
                    }
                    let arr = []
                    var myGeo = new BMap.Geocoder();
                    let carTime = ''
                    let driverTime = ''
                    let carArr = []
                    let driverArr = []
                    let SelectType = 0
                    for (let i of positions) {
                        if (i.carDate && i.driverDate) {
                            carTime = new Date(i.carDate).getTime()
                            driverTime = new Date(i.driverDate).getTime()
                            if (carTime - driverTime >= 0) {
                                arr = i.carAddress.split(',')
                                i['date'] = i.carDate
                            } else {
                                arr = i.driverAddress.split(',')
                                i['date'] = i.driverDate
                            }
                            carArr = i.carAddress.split(',')
                            driverArr = i.driverAddress.split(',')
                            SelectType = 1
                        } else {
                            if (i.carDate) {
                                arr = i.carAddress.split(',')
                                i['date'] = i.carDate
                                carArr = i.carAddress.split(',')
                                SelectType = 2
                                driverArr = []
                            }
                            if (i.driverDate) {
                                carArr = []
                                arr = i.driverAddress.split(',')
                                i['date'] = i.driverDate
                                driverArr = i.driverAddress.split(',')
                                SelectType = 3
                            }
                        }
                        i['driverAddresa'] = arr
                        i['carpoint'] = carArr
                        i['driverpoint'] = driverArr
                        if (SelectType == 1) {
                            myGeo.getLocation(new BMap.Point(i.driverAddresa[0], i.driverAddresa[1]), function(result) {
                                if (result) {
                                    i.Address = result.address
                                }
                            })
                            myGeo.getLocation(new BMap.Point(i.carpoint[0], i.carpoint[1]), function(result) {
                                if (result) {
                                    i.carAddress = result.address
                                }
                            })
                            myGeo.getLocation(new BMap.Point(i.driverpoint[0], i.driverpoint[1]), function(result) {
                                if (result) {
                                    i.driverAddress = result.address
                                }
                            })
                        } else if (SelectType == 2) {
                            myGeo.getLocation(new BMap.Point(i.carpoint[0], i.carpoint[1]), function(result) {
                                if (result) {
                                    i.carAddress = result.address
                                    i.Address = result.address
                                        //i.driverAddress = ''
                                } else {
                                    i.driverAddress = '未知的地址'
                                    i.Address = '未知的地址'
                                    i.carAddress = '未知的地址'
                                }
                            })
                        } else if (SelectType == 3) {

                            myGeo.getLocation(new BMap.Point(i.driverpoint[0], i.driverpoint[1]), function(result) {
                                if (result) {
                                    i.driverAddress = result.address
                                    i.Address = result.address
                                } else {
                                    i.driverAddress = '未知的地址'
                                    i.Address = '未知的地址'
                                    i.carAddress = '未知的地址'
                                }
                            })

                        }

                    }
                    //this.inputdata = positions;
                    AddMaker(positions)
                    for (let i = 0; i < positions.length; i++) {
                        $("#select").append("<option  value=" + i + ">" + positions[i].driverName + "</option>");
                    }
                    //为下拉列表添加数据
                } else {
                    this.$message({
                        message: "暂无车辆数据",
                        offset: 80
                    });
                    AddMaker()
                }
            })
        }

        $('#select').change(function() {
            if (!positions) {
                return
            }
            let i = $(this).val()
            if (i == -1) {
                return window.location.reload()
            }
            let value = positions[i]
            map.centerAndZoom(
                new BMap.Point(value.driverAddresa[0], value.driverAddresa[1]),
                20
            );
            var opts = {
                width: 290, // 信息窗口宽度
                enableMessage: true //设置允许信息窗发送短息
            };
            if (isDispatch) {
                var contents = `<div"><div style="padding-top:.2rem">姓名: <span style="padding-left:.2rem">${
			value.driverName
			}</span></div>
			<div style="padding-top:.2rem">车牌: <span style="padding-left:.2rem">${
				value.carNumber
			}</span></div>
			<div style="padding-top:.2rem">车型: <span style="padding-left:.2rem">${
				value.carType == undefined ? "暂无车型信息" : value.carType
			}</span></div>
			<div style="padding-top:.2rem">最新位置: <span style="padding-left:.2rem">${
				value.Address
			}</span></div>
			<div style="padding-top:.2rem">最新时间: <span style="padding-left:.2rem">${
				value.date
			}</span></div>
			<div style="padding-top:.2rem">车队: <span style="padding-left:.2rem">${
				value.fleetName == null || value.fleetName == ""
				? "无"
				: value.fleetName
			}</span></div>
			<div style="padding-top:.2rem">司机类型: <span >${
				value.driverType == 1
				? "公司自有"
				: value.driverType == 2
				? "挂靠司机"
				: "挂靠车队"
			}</span></div>
			<div style="text-align:center;padding-top:.2rem"><button onclick="window.dang(${
				value.driverId
			},${value.driverId},${value.carId},${value.driverType},'${
			value.fleetName
			}','${
			value.driverName
			}');" style="width:50%;cursor:pointer;background-color:#FFFFFF;border:1px solid red;border-radius:15px;">调度</button></div>`;
            } else {
                var contents = `<div><div style="padding-top:.2rem">姓名: <span style="padding-left:.2rem">${
			value.driverName
			}</span></div>
			<div style="padding-top:.2rem">车牌: <span style="padding-left:.2rem">${
				value.carNumber
			}</span></div>
			<div style="padding-top:.2rem">车型: <span style="padding-left:.2rem">${
				value.carType == undefined ? "暂无车型信息" : value.carType
			}</span></div>
			<div style="padding-top:.2rem">最新位置: <span style="padding-left:.2rem">${
				value.Address
			}</span></div>
			<div style="padding-top:.2rem">最新时间: <span style="padding-left:.2rem">${
				value.date
			}</span></div>`;
            }
            var point = new BMap.Point(
                value.driverAddresa[0],
                value.driverAddresa[1]
            );
            var infoWindow = new BMap.InfoWindow(contents, opts); // 创建信息窗口对象
            map.openInfoWindow(infoWindow, point); //开启信息窗口
            //监听信息窗口关闭时将下拉列表选中值复原
            infoWindow.addEventListener('close', function(e) {
                $('#select').val(-1)
            })
        })

        function AddMaker(positions) {
            map = new BMap.Map("container");
            var point = new BMap.Point(111.069288, 26.742627);
            map.centerAndZoom(point, 7);
            map.enableScrollWheelZoom(true);
            map.enableInertialDragging(true);
            let opts = {
                width: 290, // 信息窗口宽度
                enableMessage: true //设置允许信息窗发送短息
            };
            var myIcon = new BMap.Icon(
                "http://113.98.254.118:9098/pictures/2020/01/07/a09a083b2cc24d60b8f48624eed87521347.png",
                new BMap.Size(40, 30)
            );
            console.log(positions)
            for (let i = 0; i < positions.length; i++) {
                //console.log(positions[i].driverAddresa[0])
                //console.log(positions[i].driverAddresa[1])
                let point = new BMap.Point(
                    positions[i].driverAddresa[0],
                    positions[i].driverAddresa[1]
                );
                //console.log(positions)
                let marker = new BMap.Marker(point, {
                    icon: myIcon
                }); // 创建标注
                let content = positions[i];
                map.addOverlay(marker); // 将标注添加到地图中
                new BMap.Convertor().translate(point, 0, translateCallback);
                addClickHandler(content, marker);
            }

            function translateCallback(point1) {
                console.log('回调')
                var marker1 = new BMap.Marker(point1);
                map.addOverlay(marker1);
                var label = new BMap.Label("转换后的百度坐标", {
                    offset: new BMap.Size(20, -10)
                });
                marker1.setLabel(label); //添加百度label
                map.setCenter(point1);
            }


            function addClickHandler(content, marker) {
                marker.addEventListener("click", function(e) {
                    openInfo(content, e);
                });
            }

            function setCenter(value) {
                map.centerAndZoom(new BMap.Point(value[0], value[1]), 20);
            }

            function openInfo(content, e) {
                console.log(content, e)
                var p = e.target;
                setCenter(content.driverAddresa);
                //console.log(input)
                if (isDispatch) {
                    var contents = ''
                    contents = `<div><div style="padding-top:.2rem">姓名: <span style="padding-left:.2rem">${
					content.driverName
					}</span></div>
					<div style="padding-top:.2rem">车牌: <span style="padding-left:.2rem">${
						content.carNumber
					}</span></div>
					<div style="padding-top:.2rem">车型: <span style="padding-left:.2rem">${
						content.carType == undefined ? "暂无车型信息" : content.carType
					}</span></div>
					<div style="padding-top:.2rem">最新位置: <span style="padding-left:.2rem">${
						content.Address
					}</span></div>
					<div style="padding-top:.2rem">最新时间: <span style="padding-left:.2rem">${
						content.date
					}</span></div>
					<div style="padding-top:.2rem">车队: <span style="padding-left:.2rem">${
						content.fleetName == null || content.fleetName == ""
						? "无"
						: content.fleetName
					}</span></div>
					<div style="padding-top:.2rem">司机类型: <span >${
						content.driverType == 1
						? "公司自有"
						: content.driverType == 2
						? "挂靠司机"
						: "挂靠车队"
					}</span></div>
					<div style="text-align:center;padding-top:.2rem"><button onclick="window.dang(${
						content.driverId
					},${content.driverId},${content.carId},${content.driverType},'${
					content.fleetName
					}','${
					content.driverName
					}');" style="width:50%;cursor:pointer;background-color:#FFFFFF;border:1px solid red;border-radius:15px;outline: none;">调度</button></div>`;
                } else {
                    var contents = ''
                    contents = `<div><div style="padding-top:.2rem">姓名: <span style="padding-left:.2rem">${
					content.driverName
					}</span></div>
					<div style="padding-top:.2rem">车牌: <span style="padding-left:.2rem">${
						content.carNumber
					}</span></div>
					<div style="padding-top:.2rem">车型: <span style="padding-left:.2rem">${
						content.carType == undefined ? "暂无车型信息" : content.carType
					}</span></div>
					<div style="padding-top:.2rem">最新位置: <span style="padding-left:.2rem">${
						content.Address
					}</span></div>
					<div style="padding-top:.2rem">最新时间: <span style="padding-left:.2rem">${
						content.date
					}</span></div>`;
                }
                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                var infoWindow = new BMap.InfoWindow(contents, opts); // 创建信息窗口对象
                map.openInfoWindow(infoWindow, point); //开启信息窗口
            }
        }
        // function operationOrder (){
        // 	$.ajax({
        //         url: `${config.requestUrl}/gps/findCarGpsInfoList`,
        //         type: 'get',
        //         dateType: 'json',
        //         headers: {
        //             accessToken: accessToken,
        //             equipmentType: 1,
        //             machineCode: machineCode
        //         },
        //         data: JSON.stringify(obj),
        //         success: (data) => {

        // 		}
        // 	})
        // }
        // 获取连接参数
        function getUrlData(variable) {
            // decodeURIComponent解密
            let url = location.href; //取得整个地址栏
            console.log(url);
            let query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return null;
        }
        // 确定按钮函数
        function confirm() {
            console.log('确定按钮');
            prompt.className = "prompt";
            loading.className = "loading active-loading";
            console.log(JSON.stringify(info));
            // {"driverId":13,"driverName":"李文涛","carNumber":"冀A-222","carAttributeId":2,"fleetId":null,"driverType":1,"driverAddress":"广东省深圳市龙华区龙华和平路90号靠近渤海银行(深圳龙华支行)","carType":"厢车 4.2m*1.8m*1.85m","lng":114.036233,"lat":22.664124}
            // 先判断司机属性类型
            if (bool == 'true') {
                // 判断司机是否为车队
                if (info.driverType != '3') {
                    // 司机
                    obj = {
                            orderId: orderId,
                            driverId: info.driverId,
                            carId,
                            dispathPhone: dispathPhone,
                            nodeContent: `${nickname}指定 司机 ${info.driverName} 派送订单，完成订单调度`,
                            // nickname:nickname
                            dispatchName: nickname
                        }
                        // 车队第一次
                    console.log("司机第一次调度");
                    url = `${config.requestUrl}/logistic/dispatch/insertOrderDispatchOne`;
                } else {
                    // 车队
                    obj = {
                            orderId: orderId,
                            fleetId: info.fleetId,
                            dispatchName: nickname,
                            dispathPhone: dispathPhone,
                            nodeContent: `${nickname}指定 车队 ${info.fleetName} 派送订单，完成订单调度`
                        }
                        //true 第一次调度	
                    console.log("车队第一次调度");
                    url = `${config.requestUrl}/logistic/dispatchFleet/insertDispatchFleet`;
                }
            } else {
                if (info.driverType != '3') {
                    // 司机
                    obj = {
                            orderId: orderId,
                            driverId: info.driverId,
                            carId,
                            dispathPhone: dispathPhone,
                            nodeContent: `${nickname}指定 司机 ${info.driverName} 派送订单，完成订单重新调度`,
                            // nickname:nickname
                            dispatchName: nickname
                        }
                        // false 重新调度
                    console.log("司机重新调度");
                    url = `${config.requestUrl}/logistic/dispatch/updateOrderDispatchOne`;
                } else {
                    // 车队
                    obj = {
                        orderId: orderId,
                        fleetId: info.fleetId,
                        dispatchName: nickname,
                        dispathPhone: dispathPhone,
                        nodeContent: `${nickname}指定 车队 ${info.fleetName} 派送订单，完成订单重新调度`
                    }
                    console.log("车队重新调度");
                    url = `${config.requestUrl}/logistic/dispatchFleet/updateDispatchFleet`;
                }
            }
            console.log(JSON.stringify(obj));
            $.ajax({
                url: url,
                type: 'post',
                dateType: 'json',
                headers: {
                    'Content-Type': 'application/json;charset=utf8',
                    accessToken: accessToken,
                    equipmentType: 1,
                    machineCode: machineCode
                },
                data: JSON.stringify(obj),
                success: (data) => {
                    console.log(JSON.stringify(data));
                    state = data.state;
                    if (data.state == 200) {
                        if (bool == 'true') {
                            if (info.driverType != '3') {
                                showHint('司机调度成功');
                            } else {
                                showHint("车队调度成功");
                            }
                        } else {
                            if (info.driverType != '3') {
                                showHint("司机重新调度成功");
                            } else {
                                showHint("车队重新调度成功");
                            }
                        }
                    } else if (data.state == 401) {

                    } else {
                        showHint(data.msg);
                    }
                    loading.className = "loading";
                },
                error: (err) => {
                    loading.className = "loading";
                    showHint('网络错误');
                }
            });
        }
        // 显示提示框
        function showHint(title) {
            console.log(title);
            dispatchTitle.innerHTML = title;
            dispatchHint.className = 'prompt active-prompt';
        }

        function hideHint() {
            if (state == 200) {
                uni.navigateBack({
                    delta: 1
                })
            }
            dispatchHint.className = 'prompt';
        }
        // 取消按钮函数
        function cancel() {
            console.log('取消')
            prompt.className = "prompt";
        }
        // 刷新
        function refresh() {
            return window.location.reload()
            if (timer != null) {
                clearTimeout(timer);
            }
            timer = setTimeout(() => {
                getLocation();
                getDriverAddress()
                    //ajaxMarker();
                let ref = document.getElementById("ref");
                ref.style.transform = `rotate(${deg}deg)`;
                deg += 360;
            }, 1000);
        }

        // 成功定位触发函数
        function onComplete(e) {
            console.log(JSON.stringify(e));
            let latitude, longitude;
            longitude = e.position.lng;
            latitude = e.position.lat;
            map.setZoomAndCenter(8, [longitude, latitude]);
        }
        // 失败定位触发函数
        function onError(err) {
            console.log(err);
        }
        // H5+P定位
        function getH5Location() {
            // 获取用户手机定位
            let latitude, longitude, point, newPoint, pcenter;
            plus.geolocation.getCurrentPosition(function(p) {
                console.info(JSON.stringify(p))
                latitude = p.coords.latitude;
                longitude = p.coords.longitude;
                // 同时传入缩放级别和中心点经纬度
                map.setZoomAndCenter(8, [longitude, latitude]);
            })
        }
        // 设置中心点,使地图移动
        function setCenter(value) {
            // value -> new BMap.Point(116.404, 39.915);
            map.centerAndZoom(new BMap.Point(value.lng, value.lat), 15);
        }
        // 地理坐标转换
        function getLocation(value) {
            return new Promise((resolve, reject) => {
                // 创建地理编码实例      
                var myGeo = new BMap.Geocoder();
                //逆/地址解析
                if (typeof value === 'string') {
                    // 地址解析
                    console.log('地址解析');
                    // 将地址解析结果显示在地图上，并调整地图视野    
                    myGeo.getPoint(value, function(point) {
                        resolve(point);
                    }, map);
                } else {
                    //逆解析
                    console.log('逆解析');
                    // 根据坐标得到地址描述    
                    myGeo.getLocation(value, function(result) {
                        resolve(result);
                    }, map)
                }
            })
        }
        // 后台请求数据显示覆盖物
        function ajaxMarker() {
            console.log(config.url);
            let data;
            myGeo = new BMap.Geocoder();
            $.get(`${config.requestUrl}/getData`, (res) => {
                    console.log(res);
                    if (res.state == 200) {
                        data = JSON.parse(res.data).data;
                        let ProArr = [];
                        // 多个点实例组成的数组
                        let markerList = [];
                        // 假数据
                        // data = [
                        // 	{"driverId":1,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"江西省赣州市章贡区濂溪路55号","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                        // 	{"driverId":2,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"广西壮族自治区玉林市玉州区石棠社区好邦支路万盛中央公园","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                        // 	{"driverId":3,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"陕西省咸阳市渭城区底张镇","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                        // 	{"driverId":8,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"广东省肇庆市高要区","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                        // 	{"driverId":13,"driverName":"李文涛","carNumber":"冀A-222","carType":"厢车 4.2m*1.8m*1.85m","fleetId":null,"driverType":1,"driverAddress":"广东省深圳市龙华区和平路90号"},
                        // 	{"driverId":16,"driverName":"佘诗曼","carNumber":"冀A-距离咯","carType":"厢车 5.8m*2.1m*2.2m","fleetId":1,"driverType":2,"driverAddress":"广东省深圳市龙华区和平路90号","fleetName":"石岩龙之队"}
                        // ]
                        for (let i in data) {
                            ProArr.push(
                                new Promise((resolve, reject) => {
                                    // 司机地址位置转换
                                    myGeo.getPoint(data[i].driverAddress, function(point) {
                                        console.log(point);
                                        // startAddress.push(new BMap.Point(point.lng,point.lat));
                                        let carMarker = new BMap.Marker(point, {
                                            icon: carIcon
                                        });
                                        //动画
                                        carMarker.setAnimation(BMAP_ANIMATION_BOUNCE)
                                            // alert(JSON.stringify(startAddress));
                                        map.addOverlay(carMarker);

                                        carMarker.addEventListener('click', function() {
                                            console.log(JSON.stringify(data[i]));
                                            info = data[i];
                                            carId = data[i].carId;
                                            if (data[i].driverType == 1) {
                                                driverType = '公司自有';
                                            }
                                            if (data[i].driverType == 2) {
                                                driverType = '挂靠司机';
                                            }
                                            if (data[i].driverType == 3) {
                                                driverType = '挂靠车队';
                                            }
                                            let addHtml = `
													<div style="display:flex;justify-content: center;" id="dispatchBtn">
														<div onclick="dispatch()" style="color:#E89712;margin-top:6px;text-align:center;width:60%;outline: none; border-radius:20px;line-height:14px; height:14px;padding:6px 4px; border:1px solid #E89712;">调度</div>
													</div>
												`
                                                // let dispatchBtn = document.getElementById('dispatchBtn');
                                            if (bool == 'false' && fleetdsId != '') {
                                                if (!data[i].fleetId) {
                                                    // dispatchBtn.style.display = 'none';
                                                    // console.log(dispatchBtn)
                                                    addHtml = "";
                                                }
                                            }
                                            if (bool == 'false' && fleetdsId == '') {
                                                if (data[i].fleetId) {
                                                    // dispatchBtn.style.display = 'none';
                                                    // console.log(dispatchBtn)
                                                    addHtml = "";
                                                }
                                            }
                                            htmls = `
												<div 
													style="padding:6px;height:auto;background:#fff;font-size:12px;border:1px solid #f1f1f1;"
												>   
													<div style="display:flex;justify-content: flex-end;">
														<div  style="width:20px;height:20px;display: flex;align-items: center;justify-content: center;">
														</div>
													</div>
													<div style="display:flex;">
														<div class="typeName">姓名:</div>
														<div class="content">${data[i].driverName}</div>
													</div>
													<div style="display:flex;">
														<div class="typeName">车牌:</div>
														<div class="content">${data[i].carNumber}</div>
													</div>
													<div style="display:flex;">
														<div class="typeName">车型:</div>
														<div class="content">${data[i].carType}</div>
													</div>
													<div style="display:flex;">
														<div class="typeName">位置:</div>
														<div class="content">${data[i].driverAddress}</div>
													</div>
													<div style="display:flex;">
														<div class="typeName">车队:</div>
														<div class="content">${data[i].fleetName == null || data[i].fleetName == '' ? '无' : data[i].fleetName}</div>
													</div>
													<div style="display:flex;" >
														<div class="typeName">司机类型:</div>
														<div class="content">${driverType}</div>
													</div>
													${addHtml}
												</div>
											`
                                            carMarker.openInfoWindow(new BMap.InfoWindow(htmls));
                                        })
                                    }, map)
                                })
                            )
                        }
                        Promise.all(ProArr)
                    } else {
                        data = {}
                    }
                })
                // data = {
                // 	"1":{"driverId":1,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"江西省赣州市章贡区濂溪路55号","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                // 	"2":{"driverId":2,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"广西壮族自治区玉林市玉州区石棠社区好邦支路万盛中央公园","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                // 	"3":{"driverId":3,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"陕西省咸阳市渭城区底张镇","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                // 	"8":{"driverId":8,"driverName":"李四","carNumber":"粤B-888887","carType":"冷冻车 11.8m*2.13m*2.18m","driverAddress":"广东省肇庆市高要区","fleetId":"1","driverType":"3","fleetName":"石岩龙之队"},
                // 	"13":{"driverId":13,"driverName":"李文涛","carNumber":"冀A-222","carType":"厢车 4.2m*1.8m*1.85m","fleetId":null,"driverType":1,"driverAddress":"广东省深圳市龙华区和平路90号"},
                // 	"16":{"driverId":16,"driverName":"佘诗曼","carNumber":"冀A-距离咯","carType":"厢车 5.8m*2.1m*2.2m","fleetId":1,"driverType":2,"driverAddress":"广东省深圳市龙华区和平路90号","fleetName":"石岩龙之队"}
                // }
                // 模拟数据
                // data = {
                // 	"1":{"driverId":1,"driverName":"李四","carNumber":"粤B-888887","carType":"厢车18cm*13cm*4cm","driverAddress":"广东省深圳市龙华区民治地铁站"},
                // 	"3":{"driverId":3,"driverName":"佘晓光","carNumber":"粤B-888887","carType":"厢车18cm*13cm*4cm","driverAddress":"广东省深圳市龙华区清湖地铁站金銮国际大厦"},
                // 	"4":{"driverId":4,"driverName":"nice","carNumber":"粤B-888887","carType":"厢车18cm*13cm*4cm","driverAddress":"广东省深圳市南山区腾讯大厦"},
                // }
        }

        function dispatch() {
            console.log(info);
            // document.addEventListener('UniAppJSBridgeReady', function() {
            // 	plus.nativeUI.confirm('确定调度该司机',function(res){
            // 		console.log(JSON.stringify(res));
            // 		console.log(bool);
            // 		if(res.index == 0){
            // 			console.log("确定");
            // 		}else if(res.index == 1){
            // 			console.log("取消")
            // 		}
            // 	})
            // })
            if (info.fleetId != null) {
                promptTitle.innerHTML = '确定将订单委派该车队'
            } else {
                promptTitle.innerHTML = '确定将订单委派该司机'
            }
            prompt.className = "prompt active-prompt";
        }

        function hideInfoWindow() {
            lastInfoBox.close();
        }
        // 销毁地图，并清空地图容器
        // map.destroy();
        // })
    </script>
</body>

</html>